﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Fantacid303.ProcessAffinityControl.Common;

namespace Fantacid303.ProcessAffinityControl.Manager.UserControls
{
	/// <summary>
	/// Interaction logic for CustomAffinityMaskEdit.xaml
	/// </summary>
	public partial class CustomAffinityMaskEdit : UserControl
	{
		public CustomAffinityMaskEdit()
		{
			InitializeComponent();


			var realCores = ProcessorAffinityHelper.RealProcessorCores;
			var threadingCores = ProcessorAffinityHelper.HyperThreadingCores;
			var totalCores = realCores + threadingCores;

			var i = 0;
			for (var y = 0; y < 8; y++)
			{
				for (var x = 0; x < 8; x++)
				{
					var checkBox = (CheckBox)this.grid.FindName("chkCore" + i);

					if (i + 1 <= realCores)
					{
						checkBox.Foreground = new SolidColorBrush(Colors.Green);
						checkBox.Background = new SolidColorBrush(Colors.Green);
						checkBox.FontWeight = FontWeight.FromOpenTypeWeight(800);
						checkBox.ToolTip = string.Format("Physical Core #{0}", i);
					}
					else if (i + 1 <= totalCores)
					{
						checkBox.Foreground = new SolidColorBrush(Colors.Orange);
						checkBox.Background = new SolidColorBrush(Colors.Orange);
						checkBox.FontWeight = FontWeight.FromOpenTypeWeight(800);
						checkBox.ToolTip = string.Format("Threading Core #{0}", i);
					}
					else
					{
						checkBox.IsEnabled = false;
					}

					checkBox.Content = i;
					i++;
				}
			}


			//var i = 0;
			//for (var y = 0; y < 8; y++)
			//{
			//    for (var x = 0; x < 8; x++)
			//    {
			//        var checkBox = new CheckBox();

			//        Grid.SetColumn(checkBox, x);
			//        Grid.SetRow(checkBox, y);

			//        if (i + 1 <= realCores)
			//        {
			//            checkBox.Foreground = new SolidColorBrush(Colors.Green);
			//            checkBox.Background = new SolidColorBrush(Colors.Green);
			//            checkBox.FontWeight = FontWeight.FromOpenTypeWeight(800);
			//            checkBox.ToolTip = string.Format("Physical Core #{0}", i);
			//        }
			//        else if (i + 1 <= totalCores)
			//        {
			//            checkBox.Foreground = new SolidColorBrush(Colors.Orange);
			//            checkBox.Background = new SolidColorBrush(Colors.Orange);
			//            checkBox.FontWeight = FontWeight.FromOpenTypeWeight(800);
			//            checkBox.ToolTip = string.Format("Threading Core #{0}", i);
			//        }
			//        else
			//        {
			//            checkBox.IsEnabled = false;
			//        }

			//        checkBox.Content = i;
			//        this.grid.Children.Add(checkBox);
			//        i++;
			//    }
			//}
		}
	}
}
